<template>
	<view class="social">
		<comHead :title="'管理员列表'" :isLeft="true" :isRight="false"></comHead>
		<view class="contentBox">
			<view class="searchBox">
				<image src="https://siha.vxmeng.com/static/social/search.png" mode="widthFix"></image>
				<input type="text" :placeholder="$t('sjzx.ss')" v-model="search" @confirm="getFriendList"/>
			</view>
			<view class="list">
				<radio-group name="" @change="changeCheck">
					<view class="item" v-for="(item,index) in friendList">
						<radio :value="item.user_id+''" v-if="item.type!=2"/>
						<text class="hz" v-else>{{item.type==2?'群主':'管理员'}}</text>
						<view class="l">
							<image class="img" :src="getImg(item.avatar)" mode="widthFix"></image>
							<view class="text">
								<view class="time">
									<label>
										<text>{{item.name}}</text>
									</label>
								</view>
							</view>
						</view>
					</view>
				</radio-group>
			</view>
		</view>
		<view class="bottom" @click="changeQun">
			<text :class="active.length>0?'on':''">转让群主</text>
		</view>
		
		<comPop @hidePop="popObj.isPop=false" :type="popObj.type" :title="popObj.title" @sendPopFun="sendPopFun"
				:isInput="popObj.isInput" v-if="popObj.isPop"></comPop>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:'',
				search: "",
				active:[],
				friendList:[],
				qunAdminUser:[],
				delId:'',
				popObj: {
					title: "",
					isPop: false,
					isInput: false
				},
			}
		},
		onLoad(options) {
			this.id = options.id
		},
		onShow() {
			this.getFriendList()
			this.getQunAdminUser()
		},
		methods: {
			changeQun(id){
				this.delId = id
				this.popObj = {
					title: "是否确认转让群主!",
					isPop: true,
					isInput: false,
					type: 'changeQun'
				}
			},
			sendPopFun(e) {
				console.log(e)
				if(e.type=="changeQun"){
					this.doEditQunUser()
				}
				this.popObj.isPop = false
			},
			async doEditQunUser(){
				if(this.active.length>0){
					const res = await this.$myRequest({
						url: 'api/qun/doEditQunUser',
						data: {
							qun_id:this.id,
							user_id:this.active
						}
					})
					if (res.code == 1) {
						console.log(res)
						this.$tools.showTx(res.msg)
						this.getFriendList()
						setTimeout(()=>{
							this.$tools.toTabs('/pages/social/social')
						},1000)
					}
				}
			},
			async getFriendList() {
				const res = await this.$myRequest({
					url: 'api/qun/getQunUser',
					data: {
						qun_id:this.id,
						nickname:this.search
					}
				})
				if (res.code == 1) {
					console.log(res)
					this.friendList = res.data
				}
			},
			async getQunAdminUser() {
				const res = await this.$myRequest({
					url: 'api/qun/getQunAdminUser',
					data: {
						qun_id:this.id
					}
				})
				if (res.code == 1) {
					console.log(res)
					this.qunAdminUser = res.data
				}
			},
			changeCheck(e){
				console.log(e.detail.value)
				this.active = e.detail.value
			}
		}
	}
</script>

<style lang="less" scoped>
	.social {
		display: flex;
		flex-direction: column;
		// align-items: center;
		width: 100%;

		.tabs{
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 30rpx;
			.item{
				display: flex;
				align-items: center;
				justify-content: center;
				width: 50%;
				text{
					display: inline-flex;
					color: #D8D8D8;
					font-size: 28rpx;
					border-bottom: 4rpx solid rgba(#000,0);
					padding: 10rpx 0;
					&.on{
						color: #fff;
						// font-size: 32rpx;
						border-bottom: 4rpx solid #D8D8D8;
					}
				}
			}
		}
		.contentBox {
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 670rpx;
			margin-left: 40rpx;
			.searchBox {
				width: 100%;
				height: 68rpx;
				flex-shrink: 0;
				background: rgba(#767B82, 0.3);
				border-radius: 40rpx;
				display: flex;
				align-items: center;
				padding: 0 30rpx;
				box-sizing: border-box;

				image {
					width: 29rpx;
					margin-right: 20rpx;
				}

				input {
					color: #fff;
					font-size: 28rpx;
				}
			}

			.list {
				width: 100%;
				padding-bottom: 120rpx;
				height: calc(100vh - 100rpx);
				overflow: auto;
				.item {
					display: flex;
					align-items: center;
					// justify-content: space-between;
					width: 100%;
					padding: 30rpx 0;
					border-bottom: 2rpx solid #292929;
					.hz{
						background: #FAA03E;
						color: #fff;
						padding: 5rpx 10rpx;
						border-radius: 10rpx;
						font-size: 24rpx;
						display: flex;
						align-items: center;
						justify-content: center;
					}
					.shan{
						width: 30rpx;
					}
					uni-radio,.hz{width: 90rpx;}
					>text{
						color: #fff;
						font-size: 32rpx;
					}
					.l {
						display: flex;
						align-items: center;
						width: 78%;
						margin-left: 20rpx;
						.img {
							width: 86rpx;
							height: 86rpx;
							border-radius: 50%;
							background: #FAA03E;
							display: flex;
							align-items: center;
							justify-content: center;
							image {
								width: 45rpx;
							}
						}

						.text {
							display: flex;
							flex-direction: column;
							margin-left: 20rpx;
							width: 80%;
							.time {
								display: flex;
								align-items: center;
								justify-content: space-between;
							}

							text {
								color: #fff;
								font-size: 32rpx;

								&:nth-child(2) {
									font-size: 24rpx;
									color: #999999;
									margin-top: 10rpx;
								}
							}

							.slh {
								font-size: 24rpx;
								color: #999999;
								margin-top: 10rpx;
							}
						}
					}

					.r {
						display: flex;
						align-items: center;
						.show{
							width: 140rpx;
							height: 60rpx;
							border-radius: 182rpx;
							background: linear-gradient(270deg, #5F58FD 0%, #62B6FC 100%);
							font-size: 28rpx;
							color: #fff;
							display: flex;
							align-items: center;
							justify-content: center;
						}
						>text{
							color: #666;
							font-size: 28rpx;
						}
					}
				}
			}
		}
		.bottom{
			position: fixed;
			left: 0;
			bottom: 0;
			width: 750rpx;
			height: 120rpx;
			background: #1C2128;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			padding: 0 30rpx;
			box-sizing: border-box;
			text{
				display: inline-flex;
				// width: 140rpx;
				padding: 0 20rpx;
				height: 60rpx;
				border-radius: 200rpx;
				background: #4A525E;
				align-items: center;
				justify-content: center;
				color: #BBBDBF;
				&.on{
					background: linear-gradient(290deg, #62B6FC 0%, #5F58FD 76%, #5F58FD 98%);
					color: #fff;
				}
			}
		}
	}
</style>